<?php
	/*
	 * This file is part of phpitter.
 	 * 
	 * phpitter is free software: you can redistribute it and/or modify
	 * it under the terms of the GNU General Public License as published by
	 * the Free Software Foundation, either version 3 of the License, or
	 * (at your option) any later version.
 	 * 
	 * phpitter is distributed in the hope that it will be useful,
	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	 * GNU General Public License for more details.
 	 * 
	 * You should have received a copy of the GNU General Public License
	 * along with phpitter.  If not, see <http://www.gnu.org/licenses/>.
	 *
	 * Copyright 2008 Ryan Hadley
	 */

	function redTextAbove140($entryBox)
	{
		global $updateLabel;

		$buffer = $entryBox->get_buffer();

		if ( $buffer->get_char_count() >= 141 )
		{
			$tag_table = $buffer->get_tag_table();
			$fontTags['red'] = new GtkTextTag();
			$fontTags['red']->set_property('foreground', "#ff0000");
			$tag_table->add($fontTags['red']);
			$buffer->apply_tag($fontTags['red'], $buffer->get_start_iter(), $buffer->get_end_iter());
			$updateLabel->set_text('Too long: ' . $buffer->get_char_count());
			$updateLabel->show();
		} else {
			$buffer->remove_all_tags($buffer->get_start_iter(), $buffer->get_end_iter());
			$charsLeft = 140 - $buffer->get_char_count();
			$updateLabel->set_text($charsLeft);
		}
	}

	$pluggable->registerEntryChangeCallback('redTextAbove140');
?>
